package com.huitu.whht.base.core.api.geo.sws;

import com.huitu.api.rest.AbstractApiResource;
import com.huitu.commons.PageUtils;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiResource;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiService;
import com.huitu.whht.api.core.common.response.ApiResultBuilder;
import com.huitu.whht.base.core.api.geo.sws.entities.GeoSwsQo;
import com.huitu.whht.base.core.api.geo.sws.service.IGeoSwsCoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * 说明：地表水水源地空间信息表，表名称：GEO_SWS_5T<br/>
 * 日期：2018-07-23
 *
 * @author ZhangPeng
 */
@Component
@SzyCoreApiResource
@Path("geo/sws")
public class GeoSwsCoreResource extends AbstractApiResource {

    private static final Logger logger=LoggerFactory.getLogger(GeoSwsCoreResource.class);

    private  static  final  String UUID="5cd538df-db7c-42fe-94ba-c3d0f2700d25";
    @Autowired
    @SzyCoreApiService
    private IGeoSwsCoreService geoSwsCoreService;
    @Override
    public String getUUID() {
        return UUID;
    }

    /**
     * @api {get} geo/sws/{swsCd:\w{12}} [R]根据主键查询
     * @apiDescription 根据主键查询GEO_SWS_5T地表水水源地空间信息数据
     * @apiName select by primary key
     * @apiGroup GEO_S03_0001-地表水水源地空间信息
     * @apiVersion 1.0.0
     * @apiSampleRequest geo/sws/422802000007
     * @apiParam {String}         swsCd              【必须】取用水户代码
     * @apiSuccess {String}         swsCd              地表水水源地代码
     * @apiSuccess {String}         swsNm              地表水水源地名称
     * @apiSuccess {String}         lgtd               经度
     * @apiSuccess {String}         lttd               纬度
     * @apiSuccess {String}         shape              空间信息
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "swsCd": "422802000007",
     * "swsNm": "谋道镇马蜂坳水库水源地",
     * "lgtd": 114.433288888889,
     * "lttd": 30.6326805555556,
     * "shape": "POINT (114.433288888889 30.6326805555556)",
     * "rowId": 1
     * }
     * }
     * @apiUse exceptions
     */
    @GET
    @Path("{swsCd:\\w{12}}")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectByPrimaryKey(@PathParam("swsCd") String swsCd){
        logger.info("根据主键查询 地表水水源地空间信息，参数 swsCd:{}",swsCd);
        return Response.ok(ApiResultBuilder.create(this,geoSwsCoreService.selectByPrimaryKey(swsCd))).build();
    }

    /**
     * @api {post} geo/sws/list [R]根据条件查询(含空间信息)
     * @apiDescription 根据条件查询GEO_SWS_5T地表水水源地空间信息数据(含空间信息)
     * @apiName select by filter
     * @apiGroup GEO_S03_0001-地表水水源地空间信息
     * @apiVersion 1.0.0
     * @apiSampleRequest geo/sws/list
     * @apiParam {List(String)}   swsCdList          (数组)地表水水源地代码
     * @apiParam {String}         swsCd              地表水水源地代码
     * @apiParam {String}         swsNm              地表水水源地名称
     * @apiParam {List(String)}   swsTpList          (数组)地表水水源地类型
     * @apiParam {Double}         watAMin            (最小)水面面积
     * @apiParam {Double}         watAMax            (最大)水面面积
     * @apiParam {String}         wqGoal             水质目标
     * @apiParam {List(String)}   consCondList       (数组)建设状况
     * @apiParam {Date}           putProdTmBgTm      (开始时间)投产时间
     * @apiParam {Date}           putProdTmEdTm      (结束时间)投产时间
     * @apiParam {List(String)}   runCondList        (数组)运行状况
     * @apiParam {List(String)}   wsCondList         (数组)水源供水持续状况
     * @apiParam {List(String)}   monGList           (数组)监控级别
     * @apiParam {List(String)}   wsObjList          (数组)供水对象
     * @apiParam {Double}         dywsPpMin          (最小)设计年供水人口
     * @apiParam {Double}         dywsPpMax          (最大)设计年供水人口
     * @apiParam {Double}         dywsWMin           (最小)设计年供水量
     * @apiParam {Double}         dywsWMax           (最大)设计年供水量
     * @apiParam {Double}         ddwsWMin           (最小)设计日供水量
     * @apiParam {Double}         ddwsWMax           (最大)设计日供水量
     * @apiParam {List(String)}   whsManCdList       (数组)水源地管理单位代码
     * @apiParam {String}         whsManCd           水源地管理单位代码
     * @apiParam {List(String)}   whsApprCdList      (数组)水源地审批单位代码
     * @apiParam {String}         whsApprCd          水源地审批单位代码
     * @apiParam {List(String)}   emCdList           (数组)应急管理单位代码
     * @apiParam {String}         emCd               应急管理单位代码
     * @apiParam {Date}           tsBgTm             (开始时间)时间戳
     * @apiParam {Date}           tsEdTm             (结束时间)时间戳
     * @apiParam {String}         nt                 备注
     * @apiParam {Double}         firProAMin         (最小)一级保护区面积
     * @apiParam {Double}         firProAMax         (最大)一级保护区面积
     * @apiParam {Double}         secProAMin         (最小)二级保护区面积
     * @apiParam {Double}         secProAMax         (最大)二级保护区面积
     * @apiParam {Double}         norProAMin         (最小)准保护区面积
     * @apiParam {Double}         norProAMax         (最大)准保护区面积
     * @apiParam {List(String)}   isEmgList          (数组)否为应急水源地
     * @apiSuccess {String}         swsCd             取用水户代码
     * @apiSuccess {String}         swsNm             取用水户名称
     * @apiSuccess {String}         lgtd              经度
     * @apiSuccess {String}         lttd              纬度
     * @apiSuccess {String}         shape             空间信息
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "swsCd": "422802000010",
     * "swsNm": "汪营镇清江源水源地",
     * "lgtd": 114.433288888889,
     * "lttd": 30.6326805555556,
     * "shape": "POINT (114.433288888889 30.6326805555556)"
     * },
     * {
     * "swsCd": "422822000001",
     * "swsNm": "雷家河水源地",
     * "lgtd": 113.093125,
     * "lttd": 29.5690055555556,
     * "shape": "POINT (113.093125 29.5690055555556)"
     * }]
     * }
     * @apiSuccessExample 分页请求:
     * request header: Rang={max=50;size=50;field=TS DESC}
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "swsCd": "422802000010",
     * "swsNm": "汪营镇清江源水源地",
     * "lgtd": 114.433288888889,
     * "lttd": 30.6326805555556,
     * "shape": "POINT (114.433288888889 30.6326805555556)",
     * "rowId": 1
     * },
     * {
     * "swsCd": "422822000001",
     * "swsNm": "雷家河水源地",
     * "lgtd": 113.093125,
     * "lttd": 29.5690055555556,
     * "shape": "POINT (113.093125 29.5690055555556)",
     * "rowId": 2
     * }],
     * "paging": {
     * "count": 3,
     * "total": 120,
     * "finale": false,
     * "index": 1
     * }
     * }
     * @apiUse header_rang
     * @apiUse exceptions
     */
    @POST
    @Path("list")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectList(GeoSwsQo filter){
        PageUtils.startPageFromRang();
        logger.info("根据条件查询 地表水水源地空间信息，参数 GeoSwsQo:{}",filter);
        return Response.ok(ApiResultBuilder.create(this,geoSwsCoreService.selectList(filter))).build();
    }
}
